// import com.alibaba.druid.sql.ast.SQLName;
// import com.alibaba.druid.sql.ast.SQLObject;
// import com.alibaba.druid.sql.ast.SQLPartition;
// import com.alibaba.druid.sql.ast.statement.SQLCreateIndexStatement;
// import com.alibaba.druid.sql.dialect.oracle.ast.OracleSQLObject;
// import com.alibaba.druid.sql.dialect.oracle.ast.OracleSegmentAttributesImpl;
// import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.ArrayList;
// import java.util.List;

#include "OracleUsingIndexClause.h"
#include "../../../../ast/SQLName.h"
#include "../../../../ast/SQLObject.h"
#include "../../../../ast/SQLPartition.h"
#include "../../../../ast/statement/SQLCreateIndexStatement.h"
#include "../../visitor/OracleASTVisitor.h"
#include "../../../../visitor/SQLASTVisitor.h"

OracleUsingIndexClause::OracleUsingIndexClause()
{
  localPartitionIndex = std::make_shared<std::list<SQLPartition_ptr>>();
}

void OracleUsingIndexClause::accept0(SQLASTVisitor_ptr visitor)
{
  accept0(std::dynamic_pointer_cast<OracleASTVisitor>(visitor));
}

// @Override
void OracleUsingIndexClause::accept0(OracleASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(OracleUsingIndexClause)))
  {
    acceptChild(visitor, index);
    acceptChild(visitor, tablespace);
    acceptChild(visitor, storage);
  }
  visitor->endVisit(SharedObject(OracleUsingIndexClause));
}

BOOL_ptr OracleUsingIndexClause::getEnable()
{
  return enable;
}

void OracleUsingIndexClause::setEnable(BOOL_ptr enable)
{
  this->enable = enable;
}

BOOL_ptr OracleUsingIndexClause::isComputeStatistics()
{
  return computeStatistics;
}

void OracleUsingIndexClause::setComputeStatistics(BOOL_ptr computeStatistics)
{
  this->computeStatistics = computeStatistics;
}

SQLObject_ptr OracleUsingIndexClause::getIndex()
{
  return index;
}

void OracleUsingIndexClause::setIndex(SQLName_ptr x)
{
  if (x != nullptr)
  {
    x->setParent(SharedObject(OracleUsingIndexClause));
  }
  this->index = x;
}

void OracleUsingIndexClause::setIndex(SQLCreateIndexStatement_ptr x)
{
  if (x != nullptr)
  {
    x->setParent(SharedObject(OracleUsingIndexClause));
  }
  this->index = x;
}

BOOL_ptr OracleUsingIndexClause::isReverse()
{
  return reverse;
}

void OracleUsingIndexClause::setReverse(BOOL_ptr reverse)
{
  this->reverse = reverse;
}

SQLPartition_list_ptr OracleUsingIndexClause::getLocalPartitionIndex()
{
  return localPartitionIndex;
}

void OracleUsingIndexClause::cloneTo(OracleUsingIndexClause_ptr x)
{
  OracleSegmentAttributesImpl::cloneTo(x);
  if (index != nullptr)
  {
    SQLObject_ptr idx = index->clone();
    idx->setParent(x);
    x->index = idx;
  }
  x->enable = enable;
  x->computeStatistics = computeStatistics;
  x->reverse = reverse;

  for (SQLPartition_ptr p : *localPartitionIndex)
  {
    SQLPartition_ptr p2 = std::dynamic_pointer_cast<SQLPartition>(p->clone());
    p2->setParent(x);
    x->localPartitionIndex->push_back(p2);
  }
}

SQLObject_ptr OracleUsingIndexClause::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<OracleUsingIndexClause>(new OracleUsingIndexClause());
  std::shared_ptr<OracleUsingIndexClause> x = std::dynamic_pointer_cast<OracleUsingIndexClause>(clone_tmp);
  // OracleUsingIndexClause x = new OracleUsingIndexClause();
  cloneTo(x);
  return x;
}
